//
//  UIImage+CDFillImage.m
//  CuriosityDaily3
//
//  Created by donghao on 16/9/25.
//  Copyright © 2016年 theBestTeam. All rights reserved.
//

#import "UIImage+CDFillImage.h"

@implementation UIImage (CDFillImage)


- (UIImage *)fitToSize:(CGSize)size {
    
    UIGraphicsBeginImageContext(CGSizeMake(size.width, size.height));
    [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (UIImage *)imageWithTintColor:(UIColor *)tintColor {
    
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
    [tintColor setFill];
    
    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
    UIRectFill(bounds);
    
    [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0];
    
    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return tintedImage;
}

@end
